﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MSSQL_Connection;

namespace GUI_Test
{
    public partial class formMain : Form
    {
       // List<SHARED.IDb> dbs = new List<SHARED.IDb>();
        SHARED.IDb db = null;
        public formMain()
        {
            InitializeComponent();
        }

        
        private void Convert(object sender, EventArgs e)
        {
            if (validateUserInput() != string.Empty)
            {
                MessageBox.Show(validateUserInput(), "Error: Invalid Entry");
                return;
            }
        }

        private string validateUserInput()
        {
            
            string errorMessage = string.Empty;

            if (textBoxSQL.Text.Trim() == string.Empty)
            {
                errorMessage += "Please enter your SQL statement.";
                return errorMessage;               
            }
            if (textBoxSQL.Text.Contains("SELECT") == false)
            {
                errorMessage += "The SQL statement is missing keyword SELECT or has an invalid terminator.";
                return errorMessage;
            }
            if (textBoxSQL.Text.Contains(";") == false)
            {
                errorMessage += "The SQL statement is missing keyword SELECT or has an invalid terminator.";
                return errorMessage;
            }
            if (textBoxSQL.Text.Contains("FROM") == false)
            {
                errorMessage += "The SQL statement is missing keyword SELECT has an invalid terminator.";
                return errorMessage;
            }
            return errorMessage;
        }


        private void menuQuit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void cutToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (textBoxSQL.SelectedText != "")
            {
            textBoxSQL.Cut();
            }
        }

        private void menuCopy_Click(object sender, EventArgs e)
        {
            if (textBoxSQL.SelectedText != "")
            {
                textBoxSQL.Copy();
            }
        }

        private void menuPaste_Click(object sender, EventArgs e)
        {
            textBoxSQL.Paste();
        }

        private void menuUndo_Click(object sender, EventArgs e)
        {
            if (textBoxSQL.CanUndo == true)
            {
                textBoxSQL.Undo();
            }
        }


        private void menuOracle_Click(object sender, EventArgs e)
        {
            SubFormOracleConnection formChild;
            formChild = new SubFormOracleConnection();
            if (formChild.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                db = new SHARED.Oracle(formChild.textBoxOracleServerName.Text, int.Parse(formChild.textBoxOracleDBName.Text),
                    int.Parse(formChild.textBoxOracleServiceId.Text), formChild.textBoxOracleUserId.Text, formChild.textBoxOraclePassword.Text);
            }
        }

        private void btn_CreateXml_Click(object sender, EventArgs e)
        {
            
            
        }

        private void menuMSSQL_Click(object sender, EventArgs e)
        {
            SubFormMSSQLConnection formChilid;
            formChilid = new SubFormMSSQLConnection();
            
            
            if (formChilid.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                db = new SHARED.MSSQL(formChilid.textBoxMSSQLServerName.Text, formChilid.textBoxMSSQLDBName.Text,
                    formChilid.textBoxMSSQLUserId.Text, formChilid.textBoxMSSQLPassword.Text);
            }

            
        }

        private void menuMYSQL_Click(object sender, EventArgs e)
        {
            SubFormMYSQLConnection formChild;
            formChild = new SubFormMYSQLConnection();
            if (formChild.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                db = new SHARED.MSSQL(formChild.textBoxMYSQLServerName.Text, formChild.textBoxMYSQLDBName.Text,
                    formChild.textBoxMYSQLUserId.Text, formChild.textBoxMYSQLPassword.Text);
            }
        }

        private void menuAccess_Click(object sender, EventArgs e)
        {
            SubFormAccessConnection formChild;
            formChild = new SubFormAccessConnection();
            if (formChild.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
               // db = new SHARED.Access(formChild.textBoxAccessFilename.Text, formChild.textBoxAccessPassword.Text);
            }
        }

        private void textboxSQL_TextChanged(object sender, EventArgs e)
        {
            textBoxSQL.CharacterCasing = CharacterCasing.Upper;
        }

        private void toolStripStatusLabel1_Click(object sender, EventArgs e)
        {

        }

        private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        
    }
}
